<?php
namespace app\index\model;
use think\Model;
// 总单数据
class Ordered extends model{
	function finduserselect($uid){
		$res = db("Ordered")->where("user_id",$uid)->order("times desc")->limit(10)->select();
		foreach ($res as $key => $item) {
			$order = db('Orders')->where('order_id',$item['id'])->select();
			$res[$key]['orders'] = $order;
		}
		return $res;
	}
	function findID($id,$stime,$etime){
		$res = db("Ordered")->where("user_id",$id)->where('times','between time',[$stime,$etime])->select();
		foreach ($res as $key => $item) {
			$order = db('Orders')->where('order_id',$item['id'])->select();
			$res[$key]['orders'] = $order;
		}
		return $res;  
	}
	function finduserprice($id,$datatime){
		$res = db("Ordered")->alias('oed')->where("oed.user_id",$id)->join("orders os",'oed.id=os.order_id')->where('oed.datatime',$datatime)->order("oed.times desc")->select();

		foreach ($res as $key => $item) {
			$res[$key]['o'] = $item['times'].$item['id'];
			$res[$key]['win'] = $item['rate']*$item['price'];
			$rt = model("rate")->zhaorate($item['bet'],$item['colums'],$item['bets']);
            $name = $rt['name'];
			$res[$key]['content'] = inserpankous($item['bet'],$item['colums'],$item['bets'],$name);
		}
		return $res; 
	}
	function findallorder($datatime){
		$res = db("Ordered")->where('datatime',$datatime)->order("times desc")->select();
		foreach ($res as $key => $item) {
			$res[$key]['o'] = $item['times'].$item['id'];
			$order = db('Orders')->where('order_id',$item['id'])->select();
			$res[$key]['orders'] = $order;
		}
		return $res; 
	}
	
}